package com.lagou.ipersistence.io;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Yan Jiahong
 * Created on 2020/11/7
 */
public class Resources {
    /**
     * 将资源文件加载为流
     *
     * @param resource 资源文件的名称
     */
    public static InputStream getResourceAsStream(String resource) {
        return Resources.class.getClassLoader().getResourceAsStream(resource);
    }

    public static Properties getResourceAsProperties(String resource) throws IOException {
        Properties properties = new Properties();
        properties.load(getResourceAsStream(resource));
        return properties;
    }

    public static <T> Class<T> classForName(String classname) throws ClassNotFoundException {
        return (Class<T>) Class.forName(classname);
    }
}
